﻿using BLL;
using DAL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WxPayAPI;

namespace WeChat
{
    public partial class Signout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["CardId"] != null && Request.Cookies["UserName"] != null)
            {
                string CardId = HttpContext.Current.Server.UrlDecode(Request.Cookies["CardId"].Value);
                string UserName = HttpContext.Current.Server.UrlDecode(Request.Cookies["UserName"].Value);
                ApplicationLog.Write("Id:" + CardId + "Name:" + UserName + "当前用户操作退出");
            }
            else
            {
                ApplicationLog.Write("当前用户未记住密码操作退出");
            }

            //清楚cookie
            Response.Cookies["ddls"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["Name"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["txtNum"].Expires = DateTime.Now.AddDays(-1);
            Response.Cookies["PassWord"].Expires = DateTime.Now.AddDays(-1);
            Session.Abandon();


            string userAgent = Request.UserAgent;
            int wechatstate = ConfigurationSettings.AppSettings["wechatstate"] == null ? 0 : Convert.ToInt32(ConfigurationSettings.AppSettings["wechatstate"]);
            if (userAgent.ToLower().Contains("micromessenger") && wechatstate == 1) 
            {
            
            

                //注销idbind表中openid
                JsApiPay jsApiPay = new JsApiPay(this);
            jsApiPay.GetOpenidAndAccessToken();
            ApplicationLog.Write("获取openid");
            //获取收货地址js函数入口参数
            var wxEditAddrParam = jsApiPay.GetEditAddressParameters();          
            string openid = jsApiPay.openid;
            ApplicationLog.Write("获取openid值：" + openid);
            //string openid = Session["openid"].ToString();
            BindIdBLL bd = new BindIdBLL();
            var num = bd.getUserInfo4(openid.ToString());
            }
            string UntyingUrl = ConfigurationSettings.AppSettings["UntyingUrl"];

            Response.Redirect(UntyingUrl);
        }
    }
}